package com.example.myapplication;

//import android.support.v7.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapplication.R;

public class ConstellationActivity2 extends AppCompatActivity {
    //第一步：定义对象
    TextView txt_getname,txt_getbirth,txt_contentstar;
    ImageView img_imgstar;
    Button btn_back;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_constellation2);
        //第二步：绑定控件
        txt_getname=findViewById(R.id.textView_getname);
        txt_getbirth=findViewById(R.id.textView_getbirth);
        txt_contentstar=findViewById(R.id.textView_contentstar);
        img_imgstar=findViewById(R.id.imageView_imgstar);
        btn_back=findViewById(R.id.button_back);
        btn_back();

        //第三步：接收第一页传递过来的值并且显示到对应的文本控件里面
        String  str1=getIntent().getStringExtra("name");
        int myyear=getIntent().getIntExtra("year",0);
        int mymonth1=getIntent().getIntExtra("yue",0);
        int mymonth=mymonth1+1;
        int myday=getIntent().getIntExtra("ri",0);
        txt_getname.setText("你好："+str1);
        txt_getbirth.setText("您的出生日期为："+myyear+"年"+mymonth+"月"+myday+"日");

        //第四步：从12张星座图片中与日期对应的一张图片   下标：0----11
        int[]  imgarr={R.drawable.baiyang,R.drawable.jinniu,R.drawable.shuangzi,
                R.drawable.juxie,R.drawable.shizi,R.drawable.chunv,
                R.drawable.tiancheng,R.drawable.tianxie,R.drawable.sheshou,
                R.drawable.mojie,R.drawable.shuiping,R.drawable.shuangyu };

        int[] contentarr={ R.string.白羊座,R.string.金牛座,R.string.双子座,
                R.string.巨蟹座,R.string.狮子座,R.string.处女座,
                R.string.天秤座,R.string.天蝎座,R.string.射手座,
                R.string.摩羯座,R.string.水瓶座,R.string.双鱼座 };

        //如何根据选择的年月日从数组里面找对应的图片和文字呢？
        int i= find(mymonth,myday);
        img_imgstar.setImageResource(imgarr[i]);//根据数组下标显示图片
        txt_contentstar.setText(contentarr[i]);//根据数组下标显示星座性格文字

    }
    private int find(int mymonth, int myday) {
        int i=0;
        if(mymonth==3&&myday>=21||mymonth==4&&myday<=19){i=0;}
        if(mymonth==4&&myday>=20||mymonth==5&&myday<=20){i=1;}
        if ((mymonth==5&&myday>=21)||mymonth==6&&myday<=21) { i=2; }

        if ((mymonth==6&&myday>=22)||mymonth==7&&myday<=22) { i=3; }
        if ((mymonth==7&&myday>=23)||mymonth==8&&myday<=22) { i=4; }
        if ((mymonth==8&&myday>=23)||mymonth==9&&myday<=22) { i=5; }

        if ((mymonth==9&&myday>=23)||mymonth==10&&myday<=23) { i=6; }
        if ((mymonth==10&&myday>=24)||mymonth==11&&myday<=22) { i=7; }
        if ((mymonth==11&&myday>=23)||mymonth==12&&myday<=21) { i=8; }

        if ((mymonth==12&&myday>=22)||mymonth==1&&myday<=19) { i=9; }
        if ((mymonth==1&&myday>=20)||mymonth==2&&myday<=18) { i=10; }
        if ((mymonth==2&&myday>=19)||mymonth==3&&myday<=20) { i=11; }
        return  i;
    }
    private void btn_back() {
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent= new Intent();
                intent.setClass(ConstellationActivity2.this,MainActivity6.class);
                startActivity(intent);
            }
        });
    }
}
